import axios from "axios";
import { getHashQuery } from "./index";

const service = axios.create({ timeout: 3000 });

service.interceptors.request.use(
  function(config) {
    return config;
  },
  function(error) {
    return Promise.reject(error);
  }
);

const _prefix = `/`;
const tc = "sZXczvbznhjasdzdddasfgddsZXcvddbnhjhtyredwasDFGHJdYTfREaWAsa";

/**
 * 获取报名信息
 * @param {Object} params 请求数据
 */
export const getGameInfo = function(params, headers) {
  return service.get(`${_prefix}api/y2022/teamInfo`, {
    params,
    headers,
  });
};

/**
 * 注册比赛
 * @param {Object} data 请求数据
 */
export const registerGame = function(data) {
  let url = `${_prefix}api/y2022/regTeam?_tc=${tc}`;
  return service.post(url, data, {
    headers: {
      "content-type": "multipart/form-data",
    },
  });
};

/**
 * 更新战队文件
 * @param {Object} data 请求数据
 */
export const updatePlayerFile = function(data) {
  let url = `${_prefix}api/y2022/updateTeamFile?_tc=${tc}`;
  return service.post(url, data, {
    headers: {
      "content-type": "multipart/form-data",
    },
  });
};

/**
 * 取消报名
 * @param {Object} data 请求数据
 */
export const cancleRegisterGame = function(data, headers) {
  return service.post(`${_prefix}api/y2022/unregTeam?_tc=${tc}`, data, {
    headers,
  });
};

/**
 * 注册地图
 * @param {Object} data 请求数据
 */
export const registerMap = function(data, headers) {
  return service.post(`${_prefix}api/y2022/regMap?_tc=${tc}`, data, {
    headers,
  });
};

// 决赛数据
export const finalResult = function() {
  return service.get(`${_prefix}api/y2022/finalRanks?_tc=${tc}`, {
    params: {
      groupName: getHashQuery("groupName") || "1024",
    },
  });
};

// 车轮战数据
export const wheelWarResult = function(type) {
  return service.get(`${_prefix}api/y2022/wheelWarRanks?_tc=${tc}`, {
    params: {
      groupName: getHashQuery("groupName") || "1024",
      type
    },
  });
};

// AI Rank赛数据
export const aiRankResult = function() {
  return service.get(`${_prefix}api/y2022/aiRanks?_tc=${tc}`, {
    params: {
      groupName: getHashQuery("groupName") || "1024",
    },
  });
};
